package studychinese.activity;

import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.hschinese.pronunciation.R;
import com.mylhyl.circledialog.CircleDialog;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import studychinese.adapters.HopeRanContentAdapter;
import studychinese.model.RegisterBean;
import studychinese.model.UserBean;
import studychinese.utils.ToastUtils;
import studychinese.view.ColumnView;

public class HopeRankZHActivity extends BaseAcitivity {


    @Bind(R.id.title_tv)
    TextView titleTv;
    @Bind(R.id.tv_hope_rank_top_number)
    TextView tvHopeRankTopNumber;
    @Bind(R.id.tv_hope_rank_top_content)
    TextView tvHopeRankTopContent;
    @Bind(R.id.rl_hoperan0)
    RelativeLayout rlHoperan0;
    @Bind(R.id.rl_hoperan1)
    RelativeLayout rlHoperan1;
    @Bind(R.id.rl_hoperan2)
    RelativeLayout rlHoperan2;
    @Bind(R.id.rl_hoperan3)
    RelativeLayout rlHoperan3;
    @Bind(R.id.rl_hoperan4)
    RelativeLayout rlHoperan4;
    @Bind(R.id.rl_hoperan5)
    RelativeLayout rlHoperan5;
    @Bind(R.id.rl_hoperan6)
    RelativeLayout rlHoperan6;
    @Bind(R.id.lv_rankhope)
    ListView lv_rankhope;
    @Bind(R.id.scrollview_rank)
    ScrollView scrollview_rank;
    private HopeRanContentAdapter hopeRanContentAdapter;

   private String user_targetlevel="0";

    @Override
    protected int setContainer() {
        return R.layout.activity_hope_rank_zh;
    }

    @Override
    public void innitView() {
        ButterKnife.bind(this);

        lv_rankhope.setFocusable(false);
        titleTv.setText("你希望达到的级别是？");

        View view = new ColumnView(this, 0).innitView();
        View view1 = new ColumnView(this, 1).innitView();
        View view2 = new ColumnView(this, 2).innitView();
        View view3 = new ColumnView(this, 3).innitView();
        View view4 = new ColumnView(this, 4).innitView();
        View view5 = new ColumnView(this, 5).innitView();
        View view6 = new ColumnView(this, 6).innitView();


        final ImageView iv0 = (ImageView) view.findViewById(R.id.iv_homerank1);
        final ImageView iv1 = (ImageView) view1.findViewById(R.id.iv_homerank1);
        final ImageView iv2 = (ImageView) view2.findViewById(R.id.iv_homerank1);
        final ImageView iv3 = (ImageView) view3.findViewById(R.id.iv_homerank1);
        final ImageView iv4 = (ImageView) view4.findViewById(R.id.iv_homerank1);
        final ImageView iv5 = (ImageView) view5.findViewById(R.id.iv_homerank1);
        final ImageView iv6 = (ImageView) view6.findViewById(R.id.iv_homerank1);
        final TextView tv0 = (TextView) view.findViewById(R.id.tv_rank_current);
        final TextView tv1 = (TextView) view1.findViewById(R.id.tv_rank_current);
        final TextView tv2 = (TextView) view2.findViewById(R.id.tv_rank_current);
        final TextView tv3 = (TextView) view3.findViewById(R.id.tv_rank_current);
        final TextView tv_rank_number3 = (TextView) view3.findViewById(R.id.tv_rank_number);
        final TextView tv_rank_number2 = (TextView) view2.findViewById(R.id.tv_rank_number);
        final TextView tv_rank_number1 = (TextView) view1.findViewById(R.id.tv_rank_number);
        final TextView tv_rank_number0 = (TextView) view.findViewById(R.id.tv_rank_number);
        final TextView tv_rank_number4 = (TextView) view4.findViewById(R.id.tv_rank_number);
        final TextView tv4 = (TextView) view4.findViewById(R.id.tv_rank_current);
        final TextView tv5 = (TextView) view5.findViewById(R.id.tv_rank_current);
        final TextView tv6 = (TextView) view6.findViewById(R.id.tv_rank_current);

       /* view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iv0.setImageResource(R.mipmap.columnar_0_click);
                iv1.setImageResource(R.mipmap.columnar_1_unclick);
                iv2.setImageResource(R.mipmap.columnar_2_unclick);
                iv3.setImageResource(R.mipmap.columnar_3_unclick);
                iv4.setImageResource(R.mipmap.columnar_4_unclick);
                iv5.setImageResource(R.mipmap.columnar_5_unclick);
                iv6.setImageResource(R.mipmap.columnar_6_unclick);
                tv0.setText("当前");
                tv1.setText("");
                tv2.setText("");
                tv3.setText("");
                tv4.setText("");
                tv5.setText("");
                tv6.setText("");
                hopeRanContentAdapter.setBk(0);
                hopeRanContentAdapter.notifyDataSetChanged();
                tvHopeRankTopNumber.setText("0级");
            }
        });*/
        view1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iv0.setImageResource(R.mipmap.columnar_0_unclick);
                iv1.setImageResource(R.mipmap.columnar_1_click);
                iv2.setImageResource(R.mipmap.columnar_2_unclick);
                iv3.setImageResource(R.mipmap.columnar_3_unclick);
                iv4.setImageResource(R.mipmap.columnar_4_unclick);
                iv5.setImageResource(R.mipmap.columnar_5_unclick);
                iv6.setImageResource(R.mipmap.columnar_6_unclick);
                tv0.setText("当前");
                tv1.setText("目标");
                tv2.setText("");
                tv3.setText("");
                tv4.setText("");
                tv5.setText("");
                tv6.setText("");
                hopeRanContentAdapter.setBk(1);
                hopeRanContentAdapter.notifyDataSetChanged();
                tvHopeRankTopNumber.setText("1级");
                user_targetlevel="1";
            }
        });
        view2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iv0.setImageResource(R.mipmap.columnar_0_unclick);
                iv1.setImageResource(R.mipmap.columnar_1_unclick);
                iv2.setImageResource(R.mipmap.columnar_2_click);
                iv3.setImageResource(R.mipmap.columnar_3_unclick);
                iv4.setImageResource(R.mipmap.columnar_4_unclick);
                iv5.setImageResource(R.mipmap.columnar_5_unclick);
                iv6.setImageResource(R.mipmap.columnar_6_unclick);
                tv0.setText("当前");
                tv1.setText("");
                tv2.setText("目标");
                tv3.setText("");
                tv4.setText("");
                tv5.setText("");
                tv6.setText("");
                hopeRanContentAdapter.setBk(2);
                hopeRanContentAdapter.notifyDataSetChanged();
                tvHopeRankTopNumber.setText("2级");
                scrollview_rank.smoothScrollTo(0, tv_rank_number2.getTop());
                user_targetlevel="2";
            }
        });
        view3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iv0.setImageResource(R.mipmap.columnar_0_unclick);
                iv1.setImageResource(R.mipmap.columnar_1_unclick);
                iv2.setImageResource(R.mipmap.columnar_2_unclick);
                iv3.setImageResource(R.mipmap.columnar_3_click);
                iv4.setImageResource(R.mipmap.columnar_4_unclick);
                iv5.setImageResource(R.mipmap.columnar_5_unclick);
                iv6.setImageResource(R.mipmap.columnar_6_unclick);
                tv0.setText("当前");
                tv1.setText("");
                tv2.setText("");
                tv3.setText("目标");
                tv4.setText("");
                tv5.setText("");
                tv6.setText("");
                hopeRanContentAdapter.setBk(3);
                hopeRanContentAdapter.notifyDataSetChanged();
                tvHopeRankTopNumber.setText("3级");
                scrollview_rank.smoothScrollTo(0, tv_rank_number1.getTop());
                user_targetlevel="3";
            }
        });
        view4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iv0.setImageResource(R.mipmap.columnar_0_unclick);
                iv1.setImageResource(R.mipmap.columnar_1_unclick);
                iv2.setImageResource(R.mipmap.columnar_2_unclick);
                iv3.setImageResource(R.mipmap.columnar_3_unclick);
                iv4.setImageResource(R.mipmap.columnar_4_click);
                iv5.setImageResource(R.mipmap.columnar_5_unclick);
                iv6.setImageResource(R.mipmap.columnar_6_unclick);
                tv0.setText("当前");
                tv1.setText("");
                tv2.setText("");
                tv3.setText("");
                tv4.setText("目标");
                tv5.setText("");
                tv6.setText("");
                hopeRanContentAdapter.setBk(4);
                hopeRanContentAdapter.notifyDataSetChanged();
                tvHopeRankTopNumber.setText("4级");
                scrollview_rank.smoothScrollTo(0, tv_rank_number0.getTop());
                user_targetlevel="4";
            }
        });
        view5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iv0.setImageResource(R.mipmap.columnar_0_unclick);
                iv1.setImageResource(R.mipmap.columnar_1_unclick);
                iv2.setImageResource(R.mipmap.columnar_2_unclick);
                iv3.setImageResource(R.mipmap.columnar_3_unclick);
                iv4.setImageResource(R.mipmap.columnar_4_unclick);
                iv5.setImageResource(R.mipmap.columnar_5_click);
                iv6.setImageResource(R.mipmap.columnar_6_unclick);
                tv0.setText("当前");
                tv1.setText("");
                tv2.setText("");
                tv3.setText("");
                tv4.setText("");
                tv5.setText("目标");
                tv6.setText("");
                hopeRanContentAdapter.setBk(5);
                hopeRanContentAdapter.notifyDataSetChanged();
                tvHopeRankTopNumber.setText("5级");
                scrollview_rank.smoothScrollTo(0, tv0.getTop());
                user_targetlevel="4";
            }
        });
        view6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iv0.setImageResource(R.mipmap.columnar_0_unclick);
                iv1.setImageResource(R.mipmap.columnar_1_unclick);
                iv2.setImageResource(R.mipmap.columnar_2_unclick);
                iv3.setImageResource(R.mipmap.columnar_3_unclick);
                iv4.setImageResource(R.mipmap.columnar_4_unclick);
                iv5.setImageResource(R.mipmap.columnar_5_unclick);
                iv6.setImageResource(R.mipmap.columnar_6_click);
                tv0.setText("当前");
                tv1.setText("");
                tv2.setText("");
                tv3.setText("");
                tv4.setText("");
                tv5.setText("");
                tv6.setText("目标");
                hopeRanContentAdapter.setBk(6
                );
                hopeRanContentAdapter.notifyDataSetChanged();
                tvHopeRankTopNumber.setText("6级");
                lv_rankhope.setSelection(3);
                scrollview_rank.smoothScrollTo(0, lv_rankhope.getTop());
                user_targetlevel="6";
            }
        });

        rlHoperan0.addView(view);
        rlHoperan1.addView(view1);
        rlHoperan2.addView(view2);
        rlHoperan3.addView(view3);
        rlHoperan4.addView(view4);
        rlHoperan5.addView(view5);
        rlHoperan6.addView(view6);
        List<Object> objects = new ArrayList<>();
        objects.clear();
        for (int i = 0; i < 8; i++) {
            objects.add("");
        }
        hopeRanContentAdapter = new HopeRanContentAdapter(objects, this);
        lv_rankhope.setAdapter(hopeRanContentAdapter);
    }



    @OnClick({R.id.left_img, R.id.rl_hoperanbottom})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.left_img:
                this.finish();
                break;
            case R.id.rl_hoperanbottom:


                String isSduday = getIntent().getStringExtra("isSduday");
                RegisterBean.DataBean infor = UserBean.getInfor();
                if("".equals(infor.getUser_id())){
                        if("0".equals(user_targetlevel)){
                            ToastUtils.showShort("请选择目标");
                        }else {

                            if("no".equals(isSduday)){
                                infor.setUser_initlevel("0");
                                infor.setUser_curlevel("0");
                                infor.setUser_targetlevel(user_targetlevel);
                            }else {
                                infor.setUser_initlevel("1");
                                infor.setUser_curlevel("1");
                                infor.setUser_targetlevel(user_targetlevel);
                            }
                            UserBean.putUserBean(infor);
                            setDirlog();
                        }

                    }else {
                        if(user_targetlevel.equals("0")){
                            ToastUtils.showShort("请选择目标");
                        }else {
                            if("no".equals(isSduday)){
                                infor.setUser_initlevel("0");
                                infor.setUser_curlevel("0");
                                infor.setUser_targetlevel(user_targetlevel);
                            }else {
                                infor.setUser_initlevel("1");
                                infor.setUser_curlevel("1");
                                infor.setUser_targetlevel(user_targetlevel);
                            }
                            UserBean.putUserBean(infor);
                            startActivity(new Intent(this,MySeleteBasicActivity.class));
                    }

                    }





                break;
        }
    }

    private void setDirlog() {
        new CircleDialog.Builder(this)
                .setTitle("提示")
                .setText("为了生成最适合你的学习计划，请完成注册，并回答我们几个问题，好吗？")
                .setTextColor(Color.BLACK)
                .setPositive("我知道了", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        startActivity(new Intent(HopeRankZHActivity.this,LoginActivity.class).putExtra("input","tiaoguo"));
                    }
                })
                .show();
    }

}
